package com.wd.mylibrary_square.view.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.wd.mylibrary_base.R
import com.wd.mylibrary_base.bean.ConstellationListBean
import com.wd.mylibrary_square.view.activity.ZodiacActivity
import okhttp3.internal.notify
import okhttp3.internal.notifyAll


/**
 * 作者: 邢凌志
 * 时间: 2024/9/20
 * 描述: 星座匹配列表适配器
 */

class ZodiacAdapter  (
    private var context: Context,
    private var constellation: List<ConstellationListBean.Result>
):BaseAdapter(){

    override fun getCount(): Int {
        return constellation.size
    }

    override fun getItem(p0: Int): Any {
        return constellation[p0]
    }

    override fun getItemId(p0: Int): Long {
        return p0.toLong()
    }

    override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
        var view = LayoutInflater.from(context)
            .inflate(com.wd.mylibrary_square.R.layout.item_constellation, null)
        var constellationBean = constellation[p0]

        var img = view.findViewById<ImageView>(com.wd.mylibrary_square.R.id.img)
        Glide.with(context).load(constellationBean.personalImage).into(img)

        var name=view.findViewById<TextView>(com.wd.mylibrary_square.R.id.name)
        name.setText(constellationBean.nickName)

        if(constellationBean.sex==1){
            view.findViewById<TextView>(com.wd.mylibrary_square.R.id.years).text="男"
        }else{
            view.findViewById<TextView>(com.wd.mylibrary_square.R.id.years).text="女"
        }

        var button = view.findViewById<TextView>(com.wd.mylibrary_square.R.id.isConcern)

        if(constellationBean.focusStatus==1){
            button.text="关注"
        }else{
            button.text="取消关注"
        }


        button.setOnClickListener({
            if(button.text=="关注"){
                button.text=="取消关注"
                constellationBean.focusStatus==1

            }else if(button.text=="取消关注"){
                button.text="关注"
                constellationBean.focusStatus==2
            }
            guan.attention(constellationBean.friendId.toString(),constellationBean.focusStatus)
        })

        return view
    }

    interface Guanzhu{
        fun attention(attention: String,index:Int)
    }

    lateinit var guan :Guanzhu

    fun setOnGuanZhu(guanzhu: Guanzhu){
        guan=guanzhu
    }
}